<?php
declare (strict_types=1); // php的严格模式，弱类型

namespace app\admin\controller;

use app\model\UserModel;
use think\facade\Request;
use think\facade\Validate;
use think\facade\View;

/**
 * Class User
 * @package app\admin\controller
 */
class User
{
    // 用户列表
    public function index()
    {
        $userList = UserModel::select();
        View::assign('userList', $userList);
        return View::fetch();
    }
    // 用户信息删除
    public function delete()
    {
        $userId = Request::param("user_id");
        $validate = Validate::rule([
            'user_id|用户id' => 'require|between:1,' . PHP_INT_MAX,
        ]);
        if (!$validate->check(['user_id' => $userId])) {
            echo $validate->getError();
            exit();
        }

        $result = UserModel::destroy($userId);
        return View::fetch('public/tips', ['result' => $result]);
    }
}